package com.niuwa.p2p.action.customerservice;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.Namespace;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;

import com.niuwa.p2p.action.JsonAction;
import com.niuwa.p2p.entity.customer.PhoneAuth;
import com.niuwa.p2p.entity.custservice.CustServiceGroup;
import com.niuwa.p2p.entity.custservice.CustServiceUser;
import com.niuwa.p2p.entity.user.User;
import com.niuwa.p2p.service.custService.ICustGroupService;
import com.niuwa.p2p.service.custService.ICustServiceService;
import com.niuwa.p2p.service.user.IPhoneAuthService;
/**
 * 客服列表
 * @author money
 *
 */
@Namespace("/customerservice")
@Controller
public class CustServiceAction extends JsonAction{
	private static final long serialVersionUID = 1L;
	@Autowired
	private ICustGroupService custGroupService;
	
	@Autowired
	private IPhoneAuthService iPhoneAuthService;
	
	@Autowired
	private ICustServiceService custServiceService;
	@Action("toCustomerListPage")
	public String toCustomerListPage(){
		return "customerList";
	}
	
	/**
	 * 获取ob小组
	 * @return
	 */
	@Action("getOBGroup")
	public String getOBGroup(){
		List<CustServiceGroup> list = custGroupService.getOneKindGroup(getParam("groupType"));
		this.setResult(true, null, list);
		return NONE;
	}
	
	/**
	 * 获取ob客服客户列表
	 * @return
	 */
	@Action("getPageList")
	public String getPageList(){
		User user = ((User)this.getRequest().getSession().getAttribute("user"));
		String loginName = user.getLoginName();
		this.setObjectReSult(custServiceService.getCustList(getParamMap(),user.getId(),loginName));
		return NONE;
	}
	
	/**
	 * 弹屏--用户相关信息
	 */
	@Action("openUserInfo")
	public String openUserInfo(){
		String phone = getParam("PHONE");
		//查看平台是否存在该手机号
		PhoneAuth phoneAuth = iPhoneAuthService.getPhoneAuthByPhoneNo(phone);
		if(phoneAuth == null){//电话号码在平台不存在
			//查看电话号码在意向客户或者陌生客户中是否存在
			Map map = new HashMap();
			map.put("tel", phone);
			List<CustServiceUser> list =   custServiceService.getByMap(map);
			if(list != null && list.size() > 0){
				this.getRequest().setAttribute("custServiceUser", list.get(0));//通过电话号码查询，结果唯一
			}
			return "popIntentUserInfo";//意向、陌生客户详情页
		}else{//电话号码在平台存在
			//查询相关信息
			return "popUserInfo";
		}
	}
}
